import { fetchProcessListById, delProcessById, seeProcessDetailById} from '@/services/basiccapacity';

export default {
  namespace: 'process',
  state: {
    total: null,
    items: [],
    loading: false,
  },

  effects: {
    *fetch({payload}, { call, put }) {
      const response = yield call(fetchProcessListById,payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *delete({payload,callback}, { call, put }) {
      const response = yield call(delProcessById,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'del',
        payload: response,
      });
    },
    *see({payload,callback}, { call, put }) {
      const response = yield call(seeProcessDetailById,payload);
      if (callback && typeof callback === 'function') {
        callback(response);
      }
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    del(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  }
};
